import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;

public class Test_2 extends JFrame{
	
	Container contentpane;
	MenuBar MB = new MenuBar(); 
	Size_Dialog size_dialog = new Size_Dialog(this,"SizeDialog");
	int W=1200, H=1000;
	int Login_panel_select=0;
	
	Panel_1 Login_panel = new Panel_1();
	
	public Test_2()
	{
		setTitle("도서관리 프로그램 ver 1.0");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		contentpane = getContentPane();
		contentpane.setLayout(null);
		setJMenuBar(MB);
	
		if(Login_panel_select==0)
		{
			contentpane.add(Login_panel);
			Login_panel.setSize(500,70);
			Login_panel.setLocation(10,10);
			Login_panel.setLayout(null);
		}
		else if(Login_panel_select==1)
		{
			
		}
		
		setSize(W,H);
		setVisible(true);
		
	}
	public static void main(String[]args)
	{
		new Test_2();		
	}
	
	public class Panel_1 extends JPanel
	{
		JLabel ID = new JLabel("ID");
		JLabel Password = new JLabel("Password");
		
		JTextField ID_Field = new JTextField(10);
		JTextField Password_Field = new JTextField(10);
		
		JButton Login_Button = new JButton("Login");
		
		public Panel_1()
		{
			add(ID);
			ID.setSize(20,20);
			ID.setLocation(20,20);
			ID.setFont(new Font("고딕",Font.BOLD,18));
			
			add(ID_Field);
			ID_Field.setSize(80,20);
			ID_Field.setLocation(45,20);
			
			add(Password);
			Password.setSize(90,20);
			Password.setLocation(130,20);
			Password.setFont(new Font("고딕",Font.BOLD,18));
			
			add(Password_Field);
			Password_Field.setSize(80,20);
			Password_Field.setLocation(220,20);
			
			add(Login_Button);
			Login_Button.setSize(80,20);
			Login_Button.setLocation(305,20);
			Login_Button.setFont(new Font("고딕",Font.BOLD,15));
			Login_Button.setBackground(new Color(255,255,235));
			
		}
	}
	
	public class MenuBar extends JMenuBar
	{
		JMenu[] Menulist = {new JMenu("File"), new JMenu("Option")};
		JMenuItem[] FileItem = {new JMenuItem("New"), new JMenuItem("Save"), new JMenuItem("Open"), new JMenuItem("Exit")};
		JMenuItem[] OptionItem = {new JMenuItem("Size")};
		Item_Event item_event = new Item_Event();
		
		void initMenu(JMenu[] Menulist, JMenuItem[] FileItem, JMenuItem[] OptionItem)
		{
			for(int i=0; i<FileItem.length; i++)
			{
				Menulist[0].add(FileItem[i]);
				FileItem[i].addActionListener(item_event);
			}
			for(int i=0; i<OptionItem.length; i++)
			{
				Menulist[1].add(OptionItem[i]);
				OptionItem[i].addActionListener(item_event);
			}
			add(Menulist[0]);
			add(Menulist[1]);
			
			
			this.OptionItem = OptionItem;
			this.FileItem = FileItem;
			this.Menulist = Menulist;
		}
		
		public MenuBar()
		{
			initMenu(Menulist,FileItem,OptionItem);
		}
		
	    public class Item_Event implements ActionListener
		{
	    	JFileChooser chooser = new JFileChooser();
	    	FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT 파일","txt");
	    	
			public void actionPerformed(ActionEvent e)
			{
				JMenuItem temp = (JMenuItem)e.getSource();
				if(temp.getText().equals("New"))
				{
					
				}
				else if(temp.getText().equals("Save"))
				{
					chooser.setFileFilter(filter);
					int select = chooser.showSaveDialog(null);
					if(select != chooser.APPROVE_OPTION)
					{
						JOptionPane.showMessageDialog(null, "아무 작업도 선택하지 않았습니다.");
					}
					String Path=chooser.getSelectedFile().getPath();
					JOptionPane.showMessageDialog(null, "작업이 완료 되었습니다.");
				}
				else if(temp.getText().equals("Open"))
				{
					chooser.setFileFilter(filter);
					int select = chooser.showOpenDialog(null);
					if(select!=chooser.APPROVE_OPTION)
					{
						JOptionPane.showMessageDialog(null, "아무 작업도 선택하지 않았습니다.");
						return;
					}
					
					String Path = chooser.getSelectedFile().getPath();
					JOptionPane.showMessageDialog(null, "작업이 완료 되었습니다.");

				}
				else if(temp.getText().equals("Exit"))
				{
					System.exit(0);
				}
				
				else if(temp.getText().equals("Size"))
				{
					size_dialog.setVisible(true);
				}
			}
		} 
	}
	
	public class Size_Dialog extends JDialog
    {
    	JLabel Width = new JLabel("Width:");
    	JTextField Width_Field = new JTextField(4);
    	
    	JLabel Height = new JLabel("Height:");
    	JTextField Height_Field = new JTextField(4);
    	
    	JButton OK = new JButton("설정");
    	JButton Cencel = new JButton("취소");
    	
    	OK_Cencel OC = new OK_Cencel();
    	
    	public Size_Dialog(JFrame frame, String name)
    	{
    		super(frame,name);
    		setTitle("도서관리 프로그램 창 크기 설정");
    		setSize(330,130);
    		setLayout(null);
    		
    		add(Width);
    		Width.setSize(40,20);
    		Width.setLocation(30,20);
    		
    		add(Width_Field);
    		Width_Field.setSize(70,20);
    		Width_Field.setLocation(70,20);
    		
    		add(Height);
    		Height.setSize(40,20);
    		Height.setLocation(160,20);
    		
    		add(Height_Field);
    		Height_Field.setSize(70,20);
    		Height_Field.setLocation(200,20);
    		
    		add(OK);
    		OK.setSize(70,20);
    		OK.setLocation(80,50);
    		OK.addActionListener(OC);
    		
    		add(Cencel);
    		Cencel.setSize(70,20);
    		Cencel.setLocation(160,50);
    		Cencel.addActionListener(OC);
    		
    		setVisible(false);
    	}
    	
    	public class OK_Cencel implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			JButton temp =(JButton)e.getSource();
    			if(temp.getText().equals("설정"))
    			{  
    				setSize(W=Integer.parseInt(Width_Field.getText()),H=Integer.parseInt(Height_Field.getText()));
    				repaint();
    				setVisible(false);
    				
    			}
    			else if(temp.getText().equals("취소"))
    			{
    				setVisible(false);
    			}
    		}
    	}
    }
}
